#! /bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# bacula       This shell script takes care of starting and stopping
#              the bacula File daemon.
#
# chkconfig: 2345 91 99
# description: The Leading Open Source Backup Solution.
#
#  For Bacula release @VERSION@ (@DATE@) -- @DISTNAME@
#

# Source function library
. /etc/rc.d/functions.bacula

RETVAL=0
case "$1" in
    start)
        [ -x ${BACFDBIN}/bacula-fd ] && { 
            sleep 2
            echo -n "Starting the File daemon: "
            OPTIONS=''
            if [ "${FD_USER}" != '' ]; then
               OPTIONS="${OPTIONS} -u ${FD_USER}"
            fi

            if [ "${FD_GROUP}" != '' ]; then
               OPTIONS="${OPTIONS} -g ${FD_GROUP}"
            fi

            ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
            RETVAL=$?
            echo Done.
        }
        ;;
    stop)
        [ -x ${BACFDBIN}/bacula-fd ] && {
            echo -n "Stopping the File daemon: "
            killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
            RETVAL=$?
            echo Done.
        }
        ;;
    restart)
        $0 stop
        sleep 5
        $0 start
        RETVAL=$?
        ;;
    status)
        [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
        RETVAL=$?
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac
exit $RETVAL
